/**
 * 
 */
package com.kinglian.apptestg;

import java.io.IOException;
import java.util.Date;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.kinglian.apptestg.persitence.PMF;


/**
 * @author Administrator
 *
 */
public class SignServlet extends HttpServlet {
	private static final Logger log = Logger.getLogger(SignServlet.class.getName());
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
		
		UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        
        String content = req.getParameter("content");
        
        Date date = new Date();
        
        if ( content == null || content.isEmpty())
        {
        	content = "No greeting~~";
        }
        
        Content icontent = new Content(user,content,date);
        
        PersistenceManager pm = PMF.get().getPersistenceManager();
        
       try{
    	   pm.makePersistent(icontent);
       }
       catch(Exception e)
       {
    	   log.warning(e.getLocalizedMessage());
       }
       finally{
    	   pm.close();
       }
        
        resp.sendRedirect("/index.jsp");
	}

}
